package com.webchat.dao;

import com.webchat.Utils.HibernateUtil;
import com.webchat.model.UsersEntity;
import org.hibernate.Session;

/**
 * Created by YongX on 2016/8/22.
 */
public class UsersDao {
    private final Session session;

    public UsersDao(){
        session = HibernateUtil.getSessionFactory().openSession();
    }

    public UsersEntity getUser(Integer uid){
        UsersEntity entity =  session.get(UsersEntity.class, uid);
        return  entity;
    }

    public boolean update(UsersEntity usersEntity){
        session.beginTransaction();
        session.update(usersEntity);
        session.getTransaction().commit();
        return  true;
    }

    public void closeSession(){
        session.close();
    }
}
